package dht.data;

import java.util.Vector;

import dse.modules.eln.EarthLikeNetwork;
import dse.modules.eln.EarthLikeNetworkCostCalculator;

public class NetworkUtil {
	protected static Vector<Integer> entryList;

	public static void initialize(EarthLikeNetwork network) {
		entryList = new Vector<Integer>();
		EarthLikeNetworkCostCalculator networkCostCalculator = new EarthLikeNetworkCostCalculator();
		for (int i = 1; i <= network.maxNodeId(); ++i) {
			int entry = -1;
			double minDist = Double.MAX_VALUE;
			for (int j = 1; j <= network.maxNodeId(); ++j) {
				if (i == j) {
					continue;
				}
				double dist = networkCostCalculator.distance(network,
						network.lookupNode(i), network.lookupNode(j));
				if (minDist > dist) {
					minDist = dist;
					entry = j;
				}
			}
			entryList.add(entry);
		}
	}

	public static int getEntry(int fromId) {
		return entryList.get(fromId - 1);
	}
}
